package com.tupi.project.ui.activity;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.tupi.project.R;
import com.tupi.project.base.BaseActivity;
import com.tupi.project.ui.contract.HttpContract;
import com.tupi.project.ui.presenter.HttpPresenter;

import butterknife.BindView;
import butterknife.OnClick;

public class HttpActivity extends BaseActivity<HttpPresenter> implements HttpContract.View
{
    @BindView(R.id.acc) EditText mAcc;
    @BindView(R.id.pwd) EditText mPwd;
    @BindView(R.id.info) TextView mInfo;
    @BindView(R.id.login) Button mLogin;
    
    @Override
    protected int getLayout()
    {
        return R.layout.activity_http;
    }
    
    @Override
    protected void initEventAndData()
    {
        
    }
    
    @Override
    protected void initInject()
    {
        getActivityComponent().inject(this);
    }
    
    @OnClick({R.id.login,R.id.get_token})
    public void onClick(View view)
    {
        switch (view.getId())
        {
            case R.id.login:
                mPresenter.onClickLogin(mAcc.getText().toString(), mPwd.getText().toString());
                break;
            case R.id.get_token:
                mPresenter.onClickShowToken();
                break;
        }
    }
    
    
    @Override
    public void showErrorInfo(String info)
    {
        Toast.makeText(this, info, Toast.LENGTH_SHORT).show();
    }
    
    @Override
    public void showUserInfo(String info)
    {
        mInfo.setText(info);
    }
    
    @Override
    public void showToken(String token)
    {
        mInfo.setText(token);
    }
}
